// 编写一个函数，接收一个整数列表和一个整数n，返回其中所有小于n的数的平均值
object AverageOfNumbers {
    def main(args:Array[String]): Unit = {
        println("Please enter a list of integers separated by spaces:")
        val input = scala.io.StdIn.readLine()
        val list_num = input.split(" ").map(_.toInt).toList

        println("Please enter an integer n:")
        val n = scala.io.StdIn.readInt()

        val result = averageOfNumbers(list_num, n)
        println("The average of numbers smaller than " + n + " is: " + result)
    }

    def averageOfNumbers(list_num: List[Int], n: Int): Double = {
        val filteredNumbers = list_num.filter(_ < n)
        if (filteredNumbers.isEmpty) {
            0.0
        } else {
            filteredNumbers.sum.toDouble / filteredNumbers.length
        }
    }
}
